﻿
using System;
using System.Collections.Generic;

using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;
using System.Linq;
namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 探测过滤器
    /// </summary>
    [Filter("检测二维码", FilterType.Algorithm)]
    public class AlgorithmQrCodeDetect : FilterBase
    {
        private CVPointFloat[] point2Fs = new CVPointFloat[] { };

        /// <summary>
        /// 坐标信息
        /// </summary>
        [OutputParameter("坐标信息")]
        public CVPointFloat[] Point2Fs
        {
            get => point2Fs; set
            {
                point2Fs = value;
                RaisedPropertyChanged();
            }
        }
        /// <summary>
        /// 使用管道
        /// </summary>
        /// <param name="mat"></param>
        /// <returns></returns>
        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterBases, FilterBase preFilterBase)
        {
            QRCodeDetector qRCodeDetector = new QRCodeDetector();
            if (qRCodeDetector.DetectMulti(mat, out var infos))
            {
                Point2Fs = infos.Select(p => (CVPointFloat)p).ToArray();
                return ResultData<Mat>.Accept(TextResource.detect_successful, mat);
            }
            else
            {
                return ResultData<Mat>.Accept(TextResource.detect_failed, mat);
            }
        }
    }
}
